<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 个人信息
 */
namespace app\smartbc\controller\api\v1;
use app\smartbc\controller\api\Base;
use app\smartbc\model\SmartbcBill;
use app\smartbc\model\SmartbcCouponUser;
use app\smartbc\model\SmartbcConfig;
use think\helper\Time;

class User extends Base{
    
    /**
     * 个人信息
     * @return void
     */
    public function initialize() {
        parent::initialize();
        $this->isUserAuth();
    }

   /**
     * 账单
     */
    public function bill(){
        $param['today'] = $this->request->param('today/d',0);
        $param['page']  = $this->request->param('page/d',1);
        $param['sign']  = $this->request->param('sign');
        $rel = $this->apiSign($param);
        if($rel['code'] != 200){
            return enjson(500,'签名验证失败');
        }
        $condition[] = ['uid','=',$this->user->id];
        $times = Time::today();
        if($param['today']){
            $condition[] = ['update_time','<',$times[1]]; //历史
        }else{  
            $condition[] = ['update_time','>',$times[0]]; //今天
        }
        $info = SmartbcBill::withAttr('update_time', function ($value, $data) {
            return date('Y-m-d H:i',$value);
        })->with(['user'=> function($query) {
            $query->field('id,face,nickname');
        }])->where($condition)->order('id desc')->page($param['page'],10)->select();
        if($info->isEmpty()){
            return enjson(204);
        }
        return enjson(200,$info);
    }
}